// 引入Sequelize模块
const Sequelize = require('sequelize');
const user = require('./user');
const artPPT = require('./artPPT');

// 引入数据库实例
const db = require('../db');
// 定义model
const downLoad = db.define('downLoad', {
    objectId: {
        type: Sequelize.STRING(20),
        allowNull: false,
        unique: true,
        primaryKey: true
    },

    userId: {
        type: Sequelize.STRING(20),
    },

    artpptId: {
        type: Sequelize.STRING(20),
    },

    createdAt: {
        type: Sequelize.DATE,
    },

    updatedAt: {
        type: Sequelize.DATE,
    },
}, {
    // 是否支持驼峰
    underscored: false,
    // MySQL数据库表名
    tableName: 'downLoad',
});

downLoad.belongsTo(user.user, {
    foreignKey: 'userId',
    as: 'user',
    onDelete: 'SET NULL',
});

downLoad.belongsTo(artPPT, {
    foreignKey: 'artpptId',
    as: 'artPPT',
    onDelete: 'SET NULL',
});

/*(async () => {
    await downLoad.sync({
        alter: true,
    });
    console.log("downLoad字段同步成功！");
})();*/


module.exports = {
    downLoad
};
